package com.loong.loong.hik.service;


import com.loong.loong.hik.api.dto.HikFaceDto;
import com.loong.loong.hik.api.dto.HikPeopleIdentifyDto;
import com.loong.loong.hik.api.entity.HikFace;
import com.loong.loong.hik.api.entity.HikFaceGroup;
import com.loong.loong.hik.api.entity.resource.HikFaceGroupResult;
import com.loong.loong.hik.property.request.face.FaceBatchAddRequestDto;
import com.loong.loong.hik.property.request.face.FaceBatchCopyRequestDto;
import com.loong.loong.hik.property.request.face.FaceBatchDelRequestDto;
import com.loong.loong.hik.property.request.face.FaceBatchQryRequestDto;
import com.loong.loong.hik.property.request.face.FaceBlackDetailRequestDto;
import com.loong.loong.hik.property.request.face.FaceBlackRestartRequestDto;
import com.loong.loong.hik.property.request.face.FaceFindBlackEventRequestDto;
import com.loong.loong.hik.property.request.face.FaceFindBlackRequestDto;
import com.loong.loong.hik.property.request.face.FaceFindFaceImgEventRequestDto;
import com.loong.loong.hik.property.request.face.FaceFindHighEventRequestDto;
import com.loong.loong.hik.property.request.face.FaceFindImgRequestDto;
import com.loong.loong.hik.property.request.face.FaceImgDownRequestDto;
import com.loong.loong.hik.property.request.face.FaceImgEventSwitchRequestDto;
import com.loong.loong.hik.property.request.face.FaceRelationRequestDto;
import com.loong.loong.hik.property.request.face.FaceResourceRequestDto;
import com.loong.loong.hik.property.request.face.FaceScoreRequestDto;
import com.loong.loong.hik.property.request.face.HikFaceGroup1vNCompareRequestDto;
import com.loong.loong.hik.property.result.face.FaceBatchQryResultVo;
import com.loong.loong.hik.property.result.face.FaceBlackDetailResultVo;
import com.loong.loong.hik.property.result.face.FaceBlackRestartResultVo;
import com.loong.loong.hik.property.result.face.FaceComparisonResultVo;
import com.loong.loong.hik.property.result.face.FaceFindBlackEventResultVo;
import com.loong.loong.hik.property.result.face.FaceFindBlackResultVo;
import com.loong.loong.hik.property.result.face.FaceFindFaceImgEventResultVo;
import com.loong.loong.hik.property.result.face.FaceFindHighEventResultVo;
import com.loong.loong.hik.property.result.face.FaceFindImgResultVo;
import com.loong.loong.hik.property.result.face.FaceGroupResult;
import com.loong.loong.hik.property.result.face.FaceGroupResultVo;
import com.loong.loong.hik.property.result.face.FaceRelationResultVo;
import com.loong.loong.hik.property.result.face.FaceResourceResultVo;
import com.loong.loong.hik.property.result.face.FaceResultVo;
import com.loong.loong.hik.property.result.face.FaceScoreResultVo;
import com.loong.loong.hik.property.result.face.HikFaceGroup1vNCompareResultVo;
import com.loong.loong.hik.property.result.face.HikPeopleResultVo;
import com.loong.loong.hik.property.urls.face.HikFaceBlackAndWhiteUrl;
import com.loong.loong.hik.property.urls.face.HikFaceImgUrl;
import com.loong.loong.hik.property.urls.face.HikFaceUrl;
import com.loong.loong.hik.util.HikUtil;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 人脸
 * @author jinyiang
 * @date 2023/3/12 14:45
 */
@Service
public class HikFaceVService {

	@Resource
	private HikUtil hikUtil;
	/**
	 * 按条件查询识别资源
	 */
	public FaceResourceResultVo resourceRecognition(FaceResourceRequestDto faceResourceRequestDto) throws Exception{
		return hikUtil.doPost(HikFaceUrl.RESOURCE_RECOGNITION, faceResourceRequestDto, FaceResourceResultVo.class);
	}

	/**
	 * 单个添加人脸分组
	 */
	public FaceGroupResult addGroup(HikFaceGroup hikFaceGroup) throws Exception{
		return hikUtil.doPost(HikFaceUrl.ADD_GROUP, hikFaceGroup, FaceGroupResult.class);
	}
	/**
	 * 删除人脸分组
	 */
	public FaceGroupResultVo delGroup(HikFaceGroupResult hikFaceGroup) throws Exception{
		return hikUtil.doPost(HikFaceUrl.DEL_GROUP, hikFaceGroup, FaceGroupResultVo.class);
	}
	/**
	 * 单个修改人脸分组
	 */
	public FaceGroupResultVo updateGroup(HikFaceGroup hikFaceGroup) throws Exception{
		return hikUtil.doPost(HikFaceUrl.UPDATE_GROUP, hikFaceGroup, FaceGroupResultVo.class);
	}
	/**
	 * 按条件查询人脸分组
	 */
	public FaceResourceResultVo findFaceGroup(HikFaceGroup hikFaceGroup) throws Exception{
		return hikUtil.doPost(HikFaceUrl.FIND_FACE_GROUP, hikFaceGroup, FaceResourceResultVo.class);
	}
	/**
	 * 单个添加人脸
	 * @param hikFaceDto
	 */
	public FaceResultVo add(HikFaceDto hikFaceDto) throws Exception{
		return hikUtil.doPost(HikFaceUrl.ADD, hikFaceDto, FaceResultVo.class);
	}
	/**
	 * 批量添加人脸分组
	 */
	public FaceGroupResultVo batchAdd(FaceBatchAddRequestDto faceBatchAddRequestDto) throws Exception{
		return hikUtil.doPost(HikFaceUrl.BATCH_ADD, faceBatchAddRequestDto, FaceGroupResultVo.class);
	}
	/**
	 * 批量删除人脸分组
	 */
	public FaceGroupResultVo batchDel(FaceBatchDelRequestDto faceBatchDelRequestDto) throws Exception{
		return hikUtil.doPost(HikFaceUrl.BATCH_DEL, faceBatchDelRequestDto, FaceGroupResultVo.class);
	}

	/**
	 * 单个修改人脸
	 * @param hikFaceDto
	 */
	public FaceResultVo update(HikFaceDto hikFaceDto)throws Exception{
		return hikUtil.doPost(HikFaceUrl.UPDATE, hikFaceDto, FaceResultVo.class);
	}

	/**
	 * 按条件批量查询人脸
	 */
	public FaceBatchQryResultVo findFaceGroup(FaceBatchQryRequestDto faceBatchQryRequestDto)throws Exception{
		return hikUtil.doPost(HikFaceUrl.FIND_FACE_GROUP, faceBatchQryRequestDto, FaceBatchQryResultVo.class);
	}
	/**
	 * 按条件批量查询人脸
	 */
	public FaceRelationResultVo getFaceRelation(FaceRelationRequestDto faceBatchQryRequestDto)throws Exception{
		return hikUtil.doPost(HikFaceUrl.GET_FACE_RELATION, faceBatchQryRequestDto, FaceRelationResultVo.class);
	}
	/**
	 * 批量拷贝人脸到人脸分组
	 */
	public FaceGroupResultVo batchCopy(FaceBatchCopyRequestDto faceBatchCopyRequestDto)throws Exception{
		return hikUtil.doPost(HikFaceUrl.BATCH_COPY, faceBatchCopyRequestDto, FaceGroupResultVo.class);
	}
	/**
	 * 单个添加重点人员识别计划
	 */
	public HikPeopleResultVo addBlack(HikPeopleIdentifyDto hikPeopleIdentifyDto)throws Exception{
		return hikUtil.doPost(HikFaceBlackAndWhiteUrl.ADD_BLACK, hikPeopleIdentifyDto, HikPeopleResultVo.class);
	}
	/**
	 * 删除重点人员识别计划
	 */
	public FaceGroupResultVo delBlack(FaceRelationRequestDto faceRelationRequestDto)throws Exception{
		return hikUtil.doPost(HikFaceBlackAndWhiteUrl.DEL_BLACK, faceRelationRequestDto, FaceGroupResultVo.class);
	}
	/**
	 * 单个修改重点人员识别计划
	 */
	public FaceGroupResultVo updateBlack(HikPeopleIdentifyDto hikPeopleIdentifyDto) throws Exception{
		return hikUtil.doPost(HikFaceBlackAndWhiteUrl.UPDATE_BLACK, hikPeopleIdentifyDto, FaceGroupResultVo.class);
	}
	/**
	 * 单个查询重点人员识别计划详情
	 */
	public FaceBlackDetailResultVo detailBlack(FaceBlackDetailRequestDto faceBlackDetailRequestDto)throws Exception{
		return hikUtil.doPost(HikFaceBlackAndWhiteUrl.DETAIL_BLACK, faceBlackDetailRequestDto, FaceBlackDetailResultVo.class);
	}
	/**
	 * 查询重点人员识别计划
	 */
	public FaceFindBlackResultVo getBlack(FaceFindBlackRequestDto faceFindBlackRequestDto) throws Exception{
		return hikUtil.doPost(HikFaceBlackAndWhiteUrl.GET_BLACK, faceFindBlackRequestDto, FaceFindBlackResultVo.class);
	}
	/**
	 * 重新下发重点人员识别计划
	 */
	public FaceBlackRestartResultVo restartBlack(FaceBlackRestartRequestDto faceBlackRestartRequestDto) throws Exception{
		return hikUtil.doPost(HikFaceBlackAndWhiteUrl.RESTART_BLACK, faceBlackRestartRequestDto, FaceBlackRestartResultVo.class);
	}

	/**
	 * 单个添加陌生人识别计划
	 */
	public HikPeopleResultVo addWhite(HikPeopleIdentifyDto hikPeopleIdentifyDto)throws Exception{
		return hikUtil.doPost(HikFaceBlackAndWhiteUrl.ADD_WHITE, hikPeopleIdentifyDto, HikPeopleResultVo.class);
	}
	/**
	 * 删除陌生人识别计划
	 */
	public FaceGroupResultVo delWhite(FaceRelationRequestDto faceRelationRequestDto)throws Exception{
		return hikUtil.doPost(HikFaceBlackAndWhiteUrl.DEL_WHITE, faceRelationRequestDto, FaceGroupResultVo.class);
	}
	/**
	 * 单个修改陌生人识别计划
	 */
	public FaceGroupResultVo updateWhite(HikPeopleIdentifyDto hikPeopleIdentifyDto) throws Exception{
		return hikUtil.doPost(HikFaceBlackAndWhiteUrl.UPDATE_WHITE, hikPeopleIdentifyDto, FaceGroupResultVo.class);
	}
	/**
	 * 单个查询陌生人识别计划详情
	 */
	public FaceBlackDetailResultVo detailWhite(FaceBlackDetailRequestDto faceBlackDetailRequestDto)throws Exception{
		return hikUtil.doPost(HikFaceBlackAndWhiteUrl.DETAIL_WHITE, faceBlackDetailRequestDto, FaceBlackDetailResultVo.class);
	}
	/**
	 * 查询陌生人识别计划
	 */
	public FaceFindBlackResultVo getWhite(FaceFindBlackRequestDto faceFindBlackRequestDto) throws Exception{
		return hikUtil.doPost(HikFaceBlackAndWhiteUrl.GET_WHITE, faceFindBlackRequestDto, FaceFindBlackResultVo.class);
	}
	/**
	 * 重新下发陌生人识别计划
	 */
	public FaceBlackRestartResultVo restartWhite(FaceBlackRestartRequestDto faceBlackRestartRequestDto) throws Exception{
		return hikUtil.doPost(HikFaceBlackAndWhiteUrl.RESTART_WHITE, faceBlackRestartRequestDto, FaceBlackRestartResultVo.class);
	}
	/**
	 * 抓拍计划配置开关
	 */
	public FaceBlackRestartResultVo imgEventSwitch(FaceImgEventSwitchRequestDto faceImgEventSwitchRequestDto) throws Exception{
		return hikUtil.doPost(HikFaceImgUrl.IMG_EVENT_SWITCH, faceImgEventSwitchRequestDto, FaceBlackRestartResultVo.class);
	}

	//人脸应用
	/**
	 * 人脸分组1VN检索
	 */
	public HikFaceGroup1vNCompareResultVo imgOneToMany(HikFaceGroup1vNCompareRequestDto hikFaceGroup1vNCompareRequestDto) throws Exception{
		return hikUtil.doPost(HikFaceImgUrl.ONE_TO_MANY, hikFaceGroup1vNCompareRequestDto, HikFaceGroup1vNCompareResultVo.class);
	}

	/**
	 * 人脸分组1V1检索
	 */
	public FaceComparisonResultVo imgOneToOne(FaceImgDownRequestDto faceImgDownRequestDto) throws Exception{
		return hikUtil.doPost(HikFaceImgUrl.ONE_TO_MANY, faceImgDownRequestDto, FaceComparisonResultVo.class);
	}
	/**
	 * 人脸评分
	 */
	public FaceScoreResultVo scoreFace(FaceScoreRequestDto faceScoreRequestDto) throws Exception{
		if (faceScoreRequestDto!=null&& (StringUtils.isEmpty(faceScoreRequestDto.getFacePicBinaryData())||StringUtils.isEmpty(faceScoreRequestDto.getFacePicUrl()))){
			return null;
		}
		return hikUtil.doPost(HikFaceImgUrl.SCORE_FACE, faceScoreRequestDto, FaceScoreResultVo.class);
	}

	/**
	 * 以图搜图
	 */
	public FaceFindImgResultVo findImgFace(FaceFindImgRequestDto faceFindImgRequestDto) throws Exception{
		return hikUtil.doPost(HikFaceImgUrl.FIND_IMG_FACE, faceFindImgRequestDto, FaceFindImgResultVo.class);
	}
	/**
	 * 按条件查询人脸抓拍事件
	 */
	public FaceFindFaceImgEventResultVo findFaceImgEvent(FaceFindFaceImgEventRequestDto faceFindFaceImgEventRequestDto) throws Exception{
		return hikUtil.doPost(HikFaceImgUrl.FIND_FACE_IMG_EVENT, faceFindFaceImgEventRequestDto, FaceFindFaceImgEventResultVo.class);
	}
	/**
	 * 按条件查询重点人员事件
	 */
	public FaceFindBlackEventResultVo findBlackEvent(FaceFindBlackEventRequestDto faceFindBlackEventRequestDto) throws Exception{
		return hikUtil.doPost(HikFaceImgUrl.FIND_BLACK_EVENT, faceFindBlackEventRequestDto, FaceFindBlackEventResultVo.class);
	}
	/**
	 * 按条件查询陌生人事件
	 */
	public FaceFindBlackEventResultVo findWhiteEvent(FaceFindBlackEventRequestDto faceFindBlackEventRequestDto) throws Exception{
		return hikUtil.doPost(HikFaceImgUrl.FIND_WHITE_EVENT, faceFindBlackEventRequestDto, FaceFindBlackEventResultVo.class);
	}
	/**
	 * 按条件查询高频人员识别事件
	 */
	public FaceFindHighEventResultVo findHighEvent(FaceFindHighEventRequestDto faceFindHighEventRequestDto) throws Exception{
		return hikUtil.doPost(HikFaceImgUrl.FIND_HIGH_EVENT, faceFindHighEventRequestDto, FaceFindHighEventResultVo.class);
	}

}
